﻿cmake_minimum_required(VERSION 3.15)
project(units_project
    VERSION 1.0.0
    LANGUAGES C CXX
    DESCRIPTION "Unit conversion library"
)

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 项目配置
# 全局选项配置
option(BUILD_SHARED_LIBS "Build as shared library (ON) or static (OFF)" OFF)
option(BUILD_LIBUNITS_EXAMPLES "Build example programs" ON)
option(BUILD_LIBUNITS_TESTS "Build test programs" OFF)

# 设置输出目录
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# 包含GNU标准安装目录
include(GNUInstallDirs)

# 添加第三方库（先构建依赖）
add_subdirectory(3rdParty)

# 添加主库
add_subdirectory(lib)

# 包配置
include(CMakePackageConfigHelpers)
configure_package_config_file(
    cmake/libunitsConfig.cmake.in
    ${CMAKE_BINARY_DIR}/libunitsConfig.cmake
    INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libunits
    PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR
)

write_basic_package_version_file(
    ${CMAKE_BINARY_DIR}/libunitsConfigVersion.cmake
    VERSION ${PROJECT_VERSION}
    COMPATIBILITY SameMajorVersion
)

install(FILES
    ${CMAKE_BINARY_DIR}/libunitsConfig.cmake
    ${CMAKE_BINARY_DIR}/libunitsConfigVersion.cmake
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libunits
)

# 可选组件
if(BUILD_LIBUNITS_EXAMPLES)
    add_subdirectory(examples)
    message("build examples for libunits")
endif()

if(BUILD_LIBUNITS_TESTS)
    enable_testing()
    add_subdirectory(tests)
endif()

# 打印配置摘要
message(STATUS "----------------------------------------")
message(STATUS "Project configuration summary:")
message(STATUS "  Build type:        ${CMAKE_BUILD_TYPE}")
message(STATUS "  Install prefix:    ${CMAKE_INSTALL_PREFIX}")
message(STATUS "  Output directories:")
message(STATUS "    Libraries:       ${CMAKE_BINARY_DIR}/lib")
message(STATUS "    Executables:     ${CMAKE_BINARY_DIR}/bin")
message(STATUS "    Libconfig++:     ${CMAKE_BINARY_DIR}/out")
message(STATUS "----------------------------------------")
